package com.tarena.lbs.activity.exception;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    /**
     * BusinessException异常捕获方法
     * @param exception
     * @return
     */
    @ExceptionHandler
    public Result doHandleBusinessException (BusinessException exception){
        log.error("BusinessException: {}", exception.getMessage());
        return Result.fail(exception.getCode(),exception.getMessage());
    }

}
